import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
url="https://m.douban.com/movie/subject/32659890/comments?start=0"
#加入反爬代理机制
headers={
    "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 SLBrowser/8.0.1.4031 SLBChan/25"
}
response=requests.get(url,headers=headers)
response.encoding="utf-8"
#返回状态值
print(response.status_code)
# print(response.text)
soup=bs(response.text,"lxml")
#获取目标
list_divs=soup.select("#comments > div")
# print(list_divs[0])
#conments=[]
for i in list_divs:
    name=i.select("div.comment > h3 > span.comment-info > a")[0].text
    price=i.select("div.comment > h3 > span.comment-info > span")[1]['title']
    time=i.select("div.comment > h3 > span.comment-info > span.comment-time")[0]['title']
    data=i.select("div.comment > p > span")[0].text
    print(price,name,time,data)
    # conments.append([name,price,time,data])

    #用TXT方式来进行存储
    with open("1.txt","a+",newline='',encoding='utf-8')as f:
        pagecomments="\t".join([name,price,time,data,"\n"])
        f.write(pagecomments)

    #用CSV方式来进行存储
    with open("1.txt","a+",newline='',encoding='utf-8')as f:





































